import { ref, reactive, nextTick, onMounted } from "vue";
import { type PaginationProps } from "@pureadmin/table";
import { ElMessage, FormInstance } from "element-plus";
import { useRoute } from 'vue-router';
import { OverdueUserList, LookInfo, IsLooked } from "@/api/stu/bankBigData";

export function useLookCustomer() {
  const route = useRoute();
  const dataList = ref<any>([]);
  const dataList2 = ref<any>([]);
  const isLook = ref(false)
  const pagination = reactive<PaginationProps>({
    total: 0,
    pageSize: 20,
    currentPage: 1,
    pageSizes: [10, 20, 50, 100],
    background: true
  });
  const pagination2 = reactive<PaginationProps>({
    total: 0,
    pageSize: 20,
    currentPage: 1,
    pageSizes: [10, 20, 50, 100],
    background: true
  });
  const columns: TableColumnList = [
    {
      label: "序号",
      type: "index",
      width: 120
    },
    {
      label: "客户名称",
      prop: "userName",
      minWidth: 200,
    },
    {
      label: "逾期时间（天）",
      prop: "overdueTime",
      minWidth: 200,
    },

    {
      label: "逾期金额（元）",
      prop: "overdueAmount",
      minWidth: 150,
    },
    {
      label: "逾期属性",
      prop: "overdueAttribute",
      minWidth: 150
    },
    {
      label: "催收难度",
      prop: "collectionDifficulty",
      minWidth: 200
    }
  ];

  const columns2: TableColumnList = [
    {
      label: "序号",
      type: "index",
      width: 120
    },
    {
      label: "客户名称",
      prop: "userName",
      minWidth: 200,
    },
    {
      label: "逾期时间(天)",
      prop: "overdueTime",
      minWidth: 200,
    },

    {
      label: "逾期金额",
      prop: "overdueAmount",
      minWidth: 150,
    },
    {
      label: "逾期属性",
      prop: "overdueAttribute",
      minWidth: 150
    },
    {
      label: "催收难度",
      prop: "collectionDifficulty",
      minWidth: 200
    }
  ];



  // 分页
  function handleSizeChange(val) {
    getCompanyCustomerList()
  }

  function handleCurrentChange(val) {
    getCompanyCustomerList()
  }

  // 分页
  function handleSizeChanges(val) {
    getRetailCustomerList()
  }

  function handleCurrentChanges(val) {
    getRetailCustomerList()
  }

  /* 模块2 end*/

  async function getCompanyCustomerList() {
    const data = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      pageIndex: pagination.currentPage,
      pageCount: pagination.pageSize,
      detailId: '1',
    };
    const res = await OverdueUserList(data);
    if (res.success) {
      pagination.total = res.data.totalCount;
      dataList.value = res.data.items;
    } else {
      ElMessage.error(res.msg);
    }
  }

  async function getRetailCustomerList() {
    const data = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      pageIndex: pagination2.currentPage,
      pageCount: pagination2.pageSize,
      detailId: '',
    };
    const res = await OverdueUserList(data);
    if (res.success) {
      pagination2.total = res.data.totalCount;
      dataList2.value = res.data.items;
    } else {
      ElMessage.error(res.msg);
    }
  }

  function handleGetList() {
    getCompanyCustomerList()
    getRetailCustomerList()
  }

  onMounted(() => {
    handleIsLOOk()
  })

  async function handleIsLOOk() {
    const data = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      module: 2
    }
    let res = await IsLooked(data)
    if (res.data) {
      isLook.value = true
      handleGetList()
    }
  }
  async function isLookChange() {
    const data = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      module: 2
    }
    let res = await LookInfo(data)
    if (res.success) {
      isLook.value = true
      handleGetList()
    } else {
      ElMessage.error(res.msg)
    }
  }

  return {
    dataList,
    dataList2,
    pagination,
    pagination2,
    columns,
    columns2,
    handleSizeChange,
    handleCurrentChange,
    handleSizeChanges,
    handleCurrentChanges,
    handleGetList,
    isLook,
    isLookChange
  }
}
